import '@babel/polyfill'
import 'lib-flexible/flexible.js'
// import 'mutationobserver-shim'
import axios from 'axios'
import Vue from 'vue'
import App from './App.vue'
import './assets/global.css'
import './plugins/element.js'
import router from './router'
import VueParticles from 'vue-particles'
import animated from 'animate.css'

Vue.use(animated)
Vue.use(VueParticles)
// 请求根路径
Vue.config.productionTip = false

// 每一个vue的组件都可以通过this直接访问到http,从而发起ajax请求
Vue.prototype.$http = axios
new Vue({
  router,
  render: h => {
    return h(App)
  }
}).$mount('#app')
axios.interceptors.request.use(config => {
  // Do something before request is sent
  console.log("请求拦截器执行")
  //判断是否存在token，如果存在将每个页面header都添加token
  config.headers.common['token'] = sessionStorage.getItem('token');
  return config;
}, (error) => {
  // Do something with request error
  return Promise.reject(error);
});

axios.interceptors.response.use(reponse => {
  // Do something with response data
  console.log("响应拦截器执行")
  return reponse;
}, (error) => {
  // Do something with response error
  return error.response.status
});

